package com.atomgit.ai.proxy.processor;

import com.alibaba.fastjson.JSON;
import com.atomgit.ai.proxy.param.PromptParam;
import com.atomgit.ai.proxy.param.inner.tongyi.TongYiParam;
import com.atomgit.ai.proxy.param.inner.tongyi.TongYiParamInput;
import com.atomgit.ai.proxy.processor.service.ParamAndResponseProcessor;
import com.atomgit.ai.proxy.vo.ModelAnswerVO;
import org.springframework.beans.BeanUtils;

/**
 * 通义千问参数与结果处理类
 */
public class ParamAndResponseProcessorForTongYi implements ParamAndResponseProcessor{
    @Override
    public String generateRequestBody(PromptParam param) {
        TongYiParam tongYiParam = new TongYiParam();
        tongYiParam.setModel(param.getVersion());
        TongYiParamInput tongYiParamInput = new TongYiParamInput();
        BeanUtils.copyProperties(param,tongYiParamInput);
        tongYiParam.setInput(tongYiParamInput);
        return JSON.toJSONString(tongYiParam);
    }

    @Override
    public ModelAnswerVO generateModelAnswerVO(String responseBody) {
        if (responseBody != null) {
            return JSON.parseObject(responseBody, ModelAnswerVO.class);
        }
        return null;
    }

}